﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace CameraSystem
{
    public class RadiaBlurEffect : CameraEffectBase
    {
        public Shader RadiaBlurShader;
        public Material RadiaBlurMaterial;

        [Range(1, 100)]
        public float Level = 10;

        [Range(0, 1)]
        public float BufferRadius = 0.5f;

        [Range(0, 1)]
        public float CenterX = 0.5f;

        [Range(0, 1)]
        public float CenterY = 0.5f;


        public override void SetArgs(params object[] args)
        {
            Level =float.Parse( args[0].ToString());
            BufferRadius = float.Parse(args[1].ToString());
            CenterX = float.Parse(args[2].ToString());
            CenterY = float.Parse(args[3].ToString());
        }

        public override void OnRender(RenderTexture src, RenderTexture dest)
        {
            if (RadiaBlurMaterial != null)
            {
                RadiaBlurMaterial.SetFloat("_Level", Level);
                RadiaBlurMaterial.SetFloat("_CenterX", CenterX);
                RadiaBlurMaterial.SetFloat("_CenterY", CenterY);
                RadiaBlurMaterial.SetFloat("_BufferRadius", BufferRadius);

                Graphics.Blit(src, dest, RadiaBlurMaterial);
            }
            else
            {
                Graphics.Blit(src, dest);
            }
        }

        private void Awake()
        {
            RadiaBlurShader = Resources.Load<Shader>("Shader/RadiaBlur/RadiaBlur");
            RadiaBlurMaterial = new Material(RadiaBlurShader);
        }

    }
}
